package practise.alogrithm.hundredInterviewQuestions.secondTime;

import practise.inherit.InitFeildTest;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

/**
 * Created by Richard on 7/26/2014.
 */
public class GetTopKElementFromArray {
    private PriorityQueue<Integer> topper ;
    private int size =0;
    public GetTopKElementFromArray(Integer size ){
        this.size = size;
        topper = new PriorityQueue<Integer>(size,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
    }

    public void add(Integer value){
        if(topper.size()<size){
            topper.add(value);
        }
        else{
            Integer temp = topper.peek();
            if(value<temp){
                topper.poll();
                topper.add(value);
            }
        }
    }
}
